/**
 * @format
 * @Author: TC
 * @Date: 2021-09-28 18:20:33
 * @Last Modified by: TC
 * @Last Modified time: 2023-02-24 00:59:28
 */

import { _decorator, Component, Label, Node } from "cc";
import { app } from "../../FrameWork/App";
import { mFrameStorageConst } from "../../FrameWork/Const/FrameStorageConst";
import { BaseComponent } from "../../FrameWork/Module/Component/BaseComponent";
import { mEventConst } from "../Const/EventConst";
const { ccclass, property } = _decorator;

@ccclass("UserInfoLayer")
export class UserInfoLayer extends BaseComponent {
    @property(Label)
    eneryTxt: Label = null; //体力
    @property(Label)
    moneyTxt: Label = null; //金币

    protected addEvent(): void {
        super.addEvent();
        app.eventMgr.register(mEventConst.UPDATE_USER_INFO, this.onUdpateInfo, this);
        this.onUdpateInfo();
    }

    protected removeEvent(): void {
        super.removeEvent();
        app.eventMgr.unregister(mEventConst.UPDATE_USER_INFO);
    }

    private onUdpateInfo(): void {
        this.eneryTxt.string = "X" + app.storageMgr.getNumber(mFrameStorageConst.ENERY);
        this.moneyTxt.string = "X" + app.storageMgr.getNumber(mFrameStorageConst.MONEY);
    }
}
